package pt.iul.dcti.poo.financemanager.accounts;

import java.util.ArrayList;

import pt.iul.dcti.poo.financemanager.date.Date;


public class DraftAccount extends Account {

	
	public DraftAccount(long id, String name) {
		super(id, name);
	}

	public DraftAccount(long id, String name, String additionalInfo, double currentBalance, Date startDate, Date endDate, ArrayList<StatementLine> listaMovimentos) {
		super(id, name, additionalInfo, currentBalance, startDate, endDate, listaMovimentos);
	}

	public long getId(){
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public  String getName(){
		return name;
	}

	public void setName(String name){
		this.name = name;
	}

	@Override
	public double estimatedAverageBalance() { 
		double average = 0.0; 
		double sum = 0.0; 
		double sumDays = 0;
		double sumDaysT=0;
		Date date = new Date();
		double numerador =0;

		int dataM = 0;
		if(listaMovimentos.isEmpty()==true){
			return average=0.0;
		}
		else dataM =date.diffInDays(listaMovimentos.get(0).getDate());
		double datam =date.diffInDays(listaMovimentos.get(listaMovimentos.size()-1).getDate());
		sumDays = datam -dataM;

		for(int i=0; i<this.getListaMovimentos().size()-1;i++){		
			double dataG =date.diffInDays(listaMovimentos.get(i).getDate());
			double dataP =date.diffInDays(listaMovimentos.get(i+1).getDate());
			sumDaysT = dataP -dataG;
			sum= sumDaysT*listaMovimentos.get(i+1).getAvailableBalance();
		}

		numerador = numerador +sum;
		average = numerador /sumDays; 

		return average; 
	}

	@Override
	public double getInterestRate() {
		return BanksConstants.normalInterestRate();
	}
	

}
